package com.lq.createPattern.singleton.type6;

public class SingletonTest06 {
    public static void main(String[] args) {
        System.out.println("双重检查推荐使用同时解决懒加载问题");
        Singleton singleton = Singleton.getInstance();
       Singleton singleton1 = Singleton.getInstance();
        System.out.println(singleton1 == singleton);
        System.out.println(singleton1.hashCode());
        System.out.println(singleton.hashCode());
    }
}

class Singleton{
   private Singleton(){};
   private static volatile Singleton instance;
   public static Singleton getInstance(){
       if(null==instance){
           synchronized (Singleton.class){
               if(instance==null){
                   instance=new Singleton();
               }
           }
       }
       return instance;
   }
}